package com.zmc.member.application.impl;

import com.zmc.common.domain.es.EsSkuEntity;
import com.zmc.common.domain.query.collection.MyCollectionFeignQuery;
import com.zmc.common.utils.JsonUtils;
import com.zmc.common.utils.PageUtils;
import com.zmc.member.application.MyCollectionApplicationService;
import com.zmc.member.infrastructure.bean.query.MyCollectionQuery;
import com.zmc.member.infrastructure.bean.vo.MyCollectionVo;
import com.zmc.member.feign.SearchFeignService;
import com.zmc.member.infrastructure.component.collection.impl.MyCollectionCacheServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author：zmc
 * @Date：2024/12/2 15:37
 */

@Service
public class MyCollectionApplicationServiceImpl implements MyCollectionApplicationService {


    @Autowired
    private MyCollectionCacheServiceImpl myCollectionCacheService;

    @Autowired
    private SearchFeignService searchFeignService;

    public static String upLoadPrefix = "http://localhost:8080/api";

    @Override
    public PageUtils pageCollection(MyCollectionQuery query) {
        PageUtils pageUtils = myCollectionCacheService.pageList(query);
        List<String> skuIds = (List<String>) pageUtils.getList();
        MyCollectionFeignQuery feignQuery = new MyCollectionFeignQuery();
        feignQuery.setSkuIds(skuIds);
        List<EsSkuEntity> list = JsonUtils.transToArrayClass(searchFeignService.collectionList(feignQuery), EsSkuEntity.class);
        list.forEach(item -> {
            item.setSkuImg(upLoadPrefix + item.getSkuImg());
        });
        pageUtils.setList(list);
        return pageUtils;
    }

    @Override
    public void save(MyCollectionVo vo) {
        myCollectionCacheService.save(vo);

    }

    @Override
    public void remove(MyCollectionVo vo) {
        myCollectionCacheService.remove(vo);
    }
}
